<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title> 登录 </title>

	<link rel="stylesheet" href="css/peng.css" />
	<link rel="stylesheet" href="css/pc.css" />
	<!-- <link rel="stylesheet" type="text/css" href="http://mishengqiang.com/sweetalert/css/sweetalert.css">
	<script type="text/javascript" src="http://mishengqiang.com/sweetalert/js/sweetalert-dev.js"></script> -->
	<link rel="stylesheet" id="swe" href="https://cdn.jsdelivr.net/npm/sweetalert2/dist/sweetalert2.min.css">
		<script src="https://cdn.jsdelivr.net/npm/sweetalert2/dist/sweetalert2.min.js"></script>

 
</head>

<body>
	 <!-- 模块脚本 -->
	 <script type="module">
		import API_CONFIG from './apiConfig.js';
		
		// 使用API_CONFIG的代码
		console.log(API_CONFIG.LOGIN_URL);
	  </script>

	<div id="content" class="content">


		<div class="banner-box">

			<form id="mainForm" class="main-form">
				<img src="img/logo.jpg" alt="">
				<h4>欢迎登陆</h4>
				<!-- 用户名 -->
				<div class="normalInput" id="cycode-box">
					<input type="text" class="input" placeholder="用户名" id="usr" class="ipt-account inp-focus">
				</div>
				<!-- 密 码 -->
				<div class="normalInput ">
					<input type="password" class="input" placeholder="密码" id="pwd" class="inp-focus">
				</div>

				<button class="fullBtnBlue" id="btn" type="button">登录</button>

			</form>


			<script src="js/js.js"></script>
			<script>
				!function () {
					function params(u, p) {
						var m = new RegExp("(?:&|/?)" + p + "=([^&$]+)").exec(u);
						return m ? m[1] : '';
					}
					if (/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == true && params(location.search, "from") != "mobile") {
						location.href = 'index.html';
					}
				}();
				var btn = document.getElementById("btn")
				var usr = document.getElementById("usr")
				var pwd = document.getElementById("pwd")
				btn.onclick = function () {
					if (usr.value == "") {
						swal.fire({
							title: "Error",
							text: "请输入用户名",
							// type: "error",
							confirmButtonText: "确 定"
						});
					} else if (pwd.value == "") {
						swal.fire({
							title: "Error",
							text: "请输入密码",
							// type: "error",
							confirmButtonText: "确 定"
						});
					} else {

						let url = API_CONFIG.LOGIN_URL; //"http://101.201.73.103:8001/bd/sys/doLogin";
						let data = {
							password: pwd.value,
							username: usr.value
						}
						Ajax.post(url, JSON.stringify(data), function (res) {  //JSON.stringify(data)
							window.localStorage.setItem('TOken',JSON.parse(res).data)
							if (JSON.parse(res).code != 0) {
								// console.log(JSON.parse(res))
								swal.fire({
									title: "error",
									text: JSON.parse(res).message,
									// type: "error",
									confirmButtonText: "确 定"
								});
							} else {
								swal.fire({
										title: 'success!',
										text: '登录成功',
										// icon: 'error',
										confirmButtonText: '确 定'
									}).then((result) => {
										if (result.isConfirmed)
											window.location.href = "searchpc.html";
										else
											swal.fire("Error!", "Coudn't delet!", "error");
									});
							}

						})

					}
				}
			</script>


</body>

</html>